package com.mx.web.model;

import java.util.List;

public class Pagination<T> {

	private Integer pageSize = 3; // 每页显示条数

	private Integer currentPage = 1; // 当前页

	private Integer totalPage = 1; // 总页数

	private Integer totalCount = 0; // 查询到的总数据量

	private List<?> items; // 数据集
	
	public Pagination() {}

	public Pagination(int currentPage, int totalPage, int totalCount) {
		this.currentPage = currentPage;
		this.totalPage = totalPage;
		this.totalCount = totalCount;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public List<?> getItems() {
		return items;
	}
	
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public void setItems(List<?> datas) {
		this.items = datas;
	}

	public Pagination<T> build(List<?> items) {
		this.setItems(items);
		int count = this.getTotalCount();
		int divisor = count / this.getPageSize();
		int remainder = count % this.getPageSize();
		this.totalPage = remainder == 0 ? divisor == 0 ? 1 : divisor : divisor + 1;
		return this;
	}
}
